#!/bin/bash
##
# Copyright (c) Microsoft Corporation.  All rights reserved.
#
# Contains settings for the OMI WS-Management Deamon.
#
#

### BEGIN INIT INFO
# Provides:          omid
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: OMI Server
# Description:       Microsoft Open Management Infrastructure (OMI) Server
### END INIT INFO

#TEMPLATE_CODEVOV_ENV#

OMI_HOME=/opt/omi
OMI_NAME="Microsoft OMI Server"

OMI_BIN=$OMI_HOME/bin/omiserver
test -x $OMI_BIN || { echo "$OMI_BIN not installed";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 5; fi; }

if test -e /etc/init.d/functions; then
    . /etc/init.d/functions
else
    echo "Could not source /etc/init.d/functions."
    exit 1
fi

RETVAL=0

case "$1" in
    start)
        LD_LIBRARY_PATH=$OMI_HOME/lib; export LD_LIBRARY_PATH
        echo -n "Starting $OMI_NAME: "
        daemon $OMI_BIN --configfile=/etc/opt/omi/conf/omiserver.conf -d
        RETVAL=$?
        echo
        ;;
    stop)
        LD_LIBRARY_PATH=$OMI_HOME/lib; export LD_LIBRARY_PATH
        echo -n "Shutting down $OMI_NAME: "
        $OMI_BIN --configfile=/etc/opt/omi/conf/omiserver.conf -s > /dev/null 2>&1
        RETVAL=$?
        if [ $RETVAL -eq 0 ]; then
            echo_success
        else
            echo_failure
        fi
        echo
        ;;
    restart)
        $0 stop
        $0 start
        RETVAL=$?
        ;;
    status)
        echo -n "Checking for service $OMI_NAME "
        status $OMI_BIN
        RETVAL=$?
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
        ;;
esac
exit $RETVAL
